package demo008;

/**
 * 使用Runnable 接口实现线程，建议使用此方法
 * 
 * @author zangyiwei 
 * @email zanglaowei@163.com
 * @date 2020年7月7日
 */
public class RunnableDemo implements Runnable{
	
	private String threadName;
  
	RunnableDemo( String name) {
      threadName = name;
	}
	   
	public void run() {
		System.out.println("Running " +  threadName );
		try {
	     for(int i = 10; i > 0; i--) {
	        System.out.println("Thread: " + threadName + ", " + i);
	        // 让线程睡眠一会
	        Thread.sleep(50);
	     }
		}catch (InterruptedException e) {
			System.out.println("Thread " +  threadName + " interrupted.");
		}
		
		System.out.println("Thread " +  threadName + " exiting.");
	}
	   
   public static  void  main(String args[]){
	   RunnableDemo runable=new RunnableDemo("testMain");
	   //使用Thread 调用Runnable	   
	   Thread threadTest=new Thread(runable);
	   threadTest.start();
   }
   
   
 

}
